let Commnd = {};
//数据库数据转换自定义的数据结构
Commnd.convertCustomData = (dbData, customColumns) => {
	let data = [];
	dbData.forEach(rowData => {
		let rowtemp = {};
		customColumns.forEach(customColumn => {
			let keys = Object.keys(rowData);
			let exists = false;
			keys.forEach(key => {
				if (key.toLowerCase() == customColumn.toLowerCase()) {
					rowtemp[customColumn] = rowData[key];
					exists = true;
					return;
				}
			})
			if (!exists) {
				rowtemp[customColumn] = Commnd.randomString();
			}
		})
		data.push(rowtemp);
	})
	return data;
}


//取随机字符串
Commnd.randomString = (len) => {
	let timestamp = new Date().getTime();
	len = len || 32;
	var random = '';
	for (i = 0; i < Commnd.exponent; i++) {
		random += Commnd.keys.charAt(Math.floor(Math.random() * Commnd.exponent));
	}
	return timestamp + '_' + random;
}

Commnd.keys = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
Commnd.exponent = Commnd.keys.length;
//短连接排号字符串 转 系统id
Commnd.To10 = (value) => {
	let result = 0;
	for (let i = 0; i < value.length; i++) {
		let x = value.length - i - 1;
		result += Commnd.keys.indexOf(value[i]) * Commnd.Pow(Commnd.exponent, x); // Math.Pow(exponent, x);
	}
	return result;
}
Commnd.Pow = (baseNo, x) => {
	let value = 1;
	while (x > 0) {
		value = value * baseNo;
		x--;
	}
	return value;
}
Commnd.replaceUrl = (url) => {
	let value = url.replace('http://s.lv-yan.com/', '');
	return value;
}
module.exports = {
	Commnd
};
